﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Pub;
//using Raize.CodeSiteLogging;

namespace LZQXT.Test.Forms
{
    public partial class FStaID : Form
    {

        DataSet ds_staRela;
        DataSet ds_staName;

        public FStaID()
        {
            InitializeComponent();
        }

        public void showDB()
        {


            CDebug.EnterMethod("核对站号");
            try
            {
                string strSQL = "SELECT * FROM P_DEFAULTVALUE WHERE ID IN(SELECT SOURCE FROM P_Product_GridPropert WHERE F_ID=" + FDBTree_lzqx.I_ID + ")";
                CDebug.Send(strSQL);
                DataSet ds1 = FDBTree_lzqx.ado1.sel1(strSQL);
                CDebug.Send("返回结果个数：" + FDBTree_lzqx.ado1.ds_count);
                try
                {
                    if (CDB.dsIsNull(ds1))
                    {
                        CDebug.ExitMethod("核对站号");
                        return;
                    }

                    for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
                    {

                        if (FDBTree_lzqx.ado1.ds.Tables[0].Rows[i]["Title"].ToString() == "站号")
                        {
                            FDBTree_lzqx.fsta_id.tboxStaID.Text = FDBTree_lzqx.ado1.ds.Tables[0].Rows[i]["Val"].ToString();

                            //if (ado2.ds.Tables[0].Rows[i_r + 1]["Title"].ToString() == "站点")
                            FDBTree_lzqx.fsta_id.tboxStaName.Text = FDBTree_lzqx.ado1.ds.Tables[0].Rows[i + 1]["Val"].ToString();
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    CDebug.SendError(ex.ToString());
                    CDebug.Send("核对站号：", ex);
                    MessageBox.Show(ex.ToString());
                }
            }
            catch (System.Exception ex)
            {
                CDebug.SendError(ex.ToString());
            }

            CDebug.ExitMethod("核对站号");
        }

        private void btnSel_Click(object sender, EventArgs e)
        {
            try
            {
                if (FDBTree_lzqx.ado1.S_Con == null || FDBTree_lzqx.ado1.S_Con == "") return;

                string strSQL_StaID = "SELECT ID,ClsID,StaID,Doc_StaID FROM P_Product_StaRela WHERE ID IN(" + tboxStaID.Text + ")";
                string sStaName = tboxStaName.Text;
                ds_staRela = FDBTree_lzqx.ado1.sel1(strSQL_StaID);
                gv_StaRela.DataSource = FDBTree_lzqx.ado1.ds.Tables[0];

                ds_staName = new DataSet();
                DataTable dt1 = new DataTable();
                DataColumn dc1 = new DataColumn();
                DataColumn dc2 = new DataColumn();
                dc1.Caption = "站号";
                dc2.Caption = "站名";
                dt1.Columns.Add(dc1);
                dt1.Columns.Add(dc2);
                ds_staName.Tables.Add(dt1);

                string[] staName = sStaName.Split(',');
                for (int i = 0; i < staName.Length; i++)
                {
                    DataRow dr_StaName = ds_staName.Tables[0].NewRow();
                    string strSQL_StaName = "SELECT * FROM P_STATION WHERE StaName LIKE '" + staName[i] + "'";
                    DataSet ds2 = FDBTree_lzqx.ado2.sel1(strSQL_StaName);
                    if (!CDB.dsIsNull(ds2))
                    {
                        dr_StaName[0] = ds2.Tables[0].Rows[0]["StaID"].ToString();
                    }
                    dr_StaName[1] = staName[i];
                    ds_staName.Tables[0].Rows.Add(dr_StaName);
                }

                gv_StaName.DataSource = ds_staName.Tables[0];

            }
            catch (System.Exception ex)
            {
                CDebug.SendError(ex.ToString());
                CDebug.Send("核对站号：", ex);
                MessageBox.Show(ex.ToString());
            }

        }

        private void FColor_Load(object sender, EventArgs e)
        {
            gv_StaRela.Dock = DockStyle.Fill;
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                FDBTree_lzqx.ado1.update(ADOTest.I_EDT);
            }
            catch (System.Exception ex)
            {
                CDebug.SendError(ex.ToString());
                CDebug.Send("提交：", ex);
                MessageBox.Show(ex.ToString());
            }

        }

        private void btnFill_Click(object sender, EventArgs e)
        {
            if (CDB.dsIsNull(ds_staRela)) return;
            if (CDB.dsIsNull(ds_staName)) return;

            try
            {
                for (int i = 0; i < FDBTree_lzqx.ado1.ds.Tables[0].Rows.Count; i++)
                {
                    if (ds_staName.Tables[0].Rows[i][0].ToString() != string.Empty)
                    {
                        FDBTree_lzqx.ado1.ds.Tables[0].Rows[i]["Doc_StaID"] = ds_staName.Tables[0].Rows[i][0].ToString();
                    }
                }
            }
            catch (System.Exception ex)
            {
                CDebug.SendError(ex.ToString());
                CDebug.Send("填充：", ex);
                MessageBox.Show(ex.ToString());
            }

        }

        private void FStaID_Load(object sender, EventArgs e)
        {
            gv_StaRela.Dock = DockStyle.Fill;
        }

    }
}